package com.lxl.pojo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class BaseResponse {
    private int code;
    private String msg;
    private Object data;

    public void fail(){
        code=BaseMsg.CODE_FAILED;
        msg=BaseMsg.MSG_FAILED;
    }
    public void success(){
        code=BaseMsg.CODE_SUCCESS;
        msg=BaseMsg.MSG_SUCCESS;
    }
    public void success(Object object){
        code=BaseMsg.CODE_SUCCESS;
        msg=BaseMsg.MSG_SUCCESS;
        data=object;
    }
    public void exception(){
        code=BaseMsg.CODE_EXCEPTION;
        msg=BaseMsg.MSG_EXCEPTION;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        String obj = null;
        try {
            obj = new ObjectMapper().writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return obj;
    }
}